//
//  StrategyDetailTableViewCell.m
//  课余时间
//
//  Created by zgr on 16/4/9.
//  Copyright © 2016年 张大少. All rights reserved.
//

#import "StrategyDetailTableViewCell.h"
#import "UIView+SDAutoLayout.h"
#import "UIImageView+WebCache.h"
#define IMGHEIGHT (KWIDTH - 16)*[[model.photoModel[i] image_height] integerValue]/[[model.photoModel[i] image_width] integerValue]
@implementation StrategyDetailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _title = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, KWIDTH - 10, 30)];
        _descText = [[UILabel alloc]init];
        _descText.sd_layout
        .leftSpaceToView(self.contentView,5)
        .topSpaceToView(_title,5)
        .autoHeightRatio(0);
        
    }
    return self;
}

-(void)setModel:(SectionsModel *)model
{
    _title.text = model.title;
    _descText.text = model.MyDescription;
    
    if (model.photoModel.count != 0) {
        for (int i = 0; i < model.photoModel.count; i++) {
          
        UIImageView *image = [[UIImageView alloc]init];
            
          image.sd_layout
            .leftSpaceToView(self.contentView,6)
            .topSpaceToView(_descText,2 * (i+1) + IMGHEIGHT * i )
            .widthIs(KWIDTH - 16)
            .heightIs((KWIDTH - 16)*[[model.photoModel[i] image_height] integerValue]/[[model.photoModel[i] image_width] integerValue]);
            [image sd_setImageWithURL:[NSURL URLWithString:[model.photoModel[i] image_url]]];
            [self.contentView addSubview:image];
            if (i == model.photoModel.count - 1) {
                _img = image;
            }
        }
        [self setupAutoHeightWithBottomView:_img bottomMargin:5];
    }
    else
    {
        [self setupAutoHeightWithBottomView:_descText bottomMargin:5];
    }
    
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
